package com.easychat.controller;

import com.easychat.annotation.GlobalInterceptor;
import com.easychat.common.LeaseException;
import com.easychat.common.PageResult;
import com.easychat.common.Result;
import com.easychat.entity.GroupInfo;
import com.easychat.entity.query.GroupInfoQuery;
import com.easychat.service.GroupInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;

/**
 * 靓号表(UserInfoBeauty)表控制层
 *
 * @author makejava
 * @since 2024-10-01 17:32:20
 */
@RestController("adminGroupController")
@RequestMapping("/admin")
public class AdminGroupController {
    /**
     * 服务对象
     */
    @Resource
    private GroupInfoService groupInfoService;

    /**
     * 展示群组
     * @param query
     * @return
     */
    @GetMapping("/loadGroup")
    @GlobalInterceptor(checkAdmin = true)
    public Result<PageResult> loadGroup(GroupInfoQuery query){
        query.setOrderBy("create_time desc");
        PageResult pageResult = groupInfoService.findListByPage(query);
        return Result.ok(pageResult);
    }
    @GetMapping("/dissolutionGroup")
    @GlobalInterceptor(checkAdmin = true)
    public Result dissolutionGroup(@NotEmpty String groupId){
        GroupInfo groupInfo = groupInfoService.getGroupInfoByGroupId(groupId,null);
        if(groupInfo == null){
            throw new LeaseException("群组不存在");
        }
        String groupOwnerId = groupInfo.getGroupOwnerId();
        groupInfoService.dissolutionGroup(groupId,groupOwnerId);

        return Result.ok();
    }


}

